<template>
	<view>

		<!-- 修改密码框弹窗 -->
		<view class="prompt-box">
			<u--form :model="form" ref="form">

				<u-form-item prop="NewPwd" border-bottom="true">
					<u--input v-model="form.NewPwd" border="none" inputAlign="left" placeholder="请填写新密码"
						type="password" />
					 
				</u-form-item>
				<u-form-item prop="confirmpwd" border-bottom="true">
					<u--input v-model="form.confirmpwd" border="none" inputAlign="left" placeholder="请确定新密码"
						type="password" />
				</u-form-item>
			</u--form>
			<u-button   type="primary" text="确定" @click="confirm"></u-button>
		</view>
	</view>

</template>

<script>
	export default {
		data() {
			var equalToPassword = (rule, value, callback) => {
				if (value !== this.form.NewPwd) {
					callback(new Error("两次输入的密码不一致"));
				} else {
					callback();
				}
			};
			var guizPassword = (rule, value, callback) => {
				const regex = /^[\w\S@!]*$/;

				if (!regex.test(String(value))) {
					callback(new Error("密码格式不对（格式：数字、大小写字母、特殊字符@！）"));
				} else {
					callback();
				}
			};
			return {

				form: {
					NewPwd: '',
					confirmpwd: "",
				},
				rules: {

					NewPwd: [{
							required: true,
							message: "新密码不能为空",
							trigger: "blur"
						}, {
							min: 6,
							max: 15,
							message: "长度在 6 到 15 个字符",
							trigger: "blur"
						},
						{
							required: true,
							validator: guizPassword,
							trigger: "blur"

						}
					],
					confirmpwd: [{
						required: true,
						message: "确认新密码不能为空",
						trigger: "blur"
					}, {
						required: true,
						validator: guizPassword,
						trigger: "blur"

					}, {
						required: true,
						validator: equalToPassword,
						trigger: "blur"
					}]
				}
			}
		},
		methods: {

			confirm() {
				this.$refs.form.validate().then(res => {
					console.log(res);
					//发请求，逻辑处理
				})

			},
			handleResetPwd() {

				this.form.NewPwd = "";
				this.form.confirmpwd = "";

			}
		},
		onReady() {
			this.$nextTick(() => {
				this.$refs.form.setRules(this.rules);
			});
		}
	}
</script>
<style lang="less">
	.prompt-box{
		padding: 15px;
	}
</style>